<?php

/**
 * This is the model class for table "data_film".
 *
 * The followings are the available columns in table 'data_film':
 * @property string $id
 * @property string $title
 * @property string $en_title
 * @property string $mobile_title
 * @property string $description
 * @property string $trailer_link
 * @property string $createddate
 * @property integer $ratting
 * @property integer $countview
 * @property integer $hot
 * @property integer $global_hot
 * @property string $order
 * @property string $global_order
 * @property integer $catid
 * @property integer $typeid
 * @property integer $couid
 * @property integer $userid
 * @property integer $episode_number
 * @property string $summary
 * @property string $price
 * @property integer $active
 */
class Film extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Film the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'data_film';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, createddate,  catid, typeid, couid, userid, episode_number', 'required'),
			array('ratting, countview, hot, global_hot, catid, typeid, couid, userid, episode_number, active', 'numerical', 'integerOnly'=>true),
			array('title, en_title, mobile_title, trailer_link,tags', 'length', 'max'=>500),
			array('order, global_order, price', 'length', 'max'=>20),
			array('description, summary', 'safe'),
			//array('mobile_title', 'file', 'types'=>'jpg, gif, png'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, en_title, mobile_title, description, trailer_link, createddate, ratting, countview, hot, global_hot, order, global_order, catid, typeid, couid, userid, episode_number, summary, price, active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the relatedMANY_MANY
		// class name for the relations automatically generated below.
		return array(
			'category'=>array(self::MANY_MANY,'Category','data_film(id,catid)','select'=>'id,name'),
			'type'=>array(self::MANY_MANY,'Type','data_film(id,typeid)','select'=>'id,name,icon'),
			'retail'=>array(self::MANY_MANY,'Package','data_film(id,price)','select'=>'id,name,price'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'en_title' => 'En Title',
			'mobile_title' => 'Mobile Title',
			'description' => 'Description',
			'trailer_link' => 'Trailer Link',
			'createddate' => 'Createddate',
			'ratting' => 'Ratting',
			'countview' => 'Countview',
			'hot' => 'Hot',
			'global_hot' => 'Global Hot',
			'order' => 'Order',
			'global_order' => 'Global Order',
			'catid' => 'Catid',
			'typeid' => 'Typeid',
			'couid' => 'Couid',
			'userid' => 'Userid',
			'episode_number' => 'Episode Number',
			'summary' => 'Summary',
			'tags'	=>'Tags',
			'price' => 'Price',
			'retail' => 'Retail Package',
			'active' => 'Active',
			'category'=>'Category',
			'type'=>'Type'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('en_title',$this->en_title,true);
		$criteria->compare('mobile_title',$this->mobile_title,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('trailer_link',$this->trailer_link,true);
		$criteria->compare('createddate',$this->createddate,true);
		$criteria->compare('ratting',$this->ratting);
		$criteria->compare('countview',$this->countview);
		if($this->hot!='')
			$criteria->compare('hot',$this->hot);
		if($this->global_hot!='')
			$criteria->compare('global_hot',$this->global_hot);
		$criteria->compare('order',$this->order);
		$criteria->compare('global_order',$this->global_order);
		if($this->catid!=0)
			$criteria->compare('catid',$this->catid);
		if($this->typeid!=0)
			$criteria->compare('typeid',$this->typeid);
		if($this->couid!=0)
			$criteria->compare('couid',$this->couid);
		$criteria->compare('userid',$this->userid);
		$criteria->compare('episode_number',$this->episode_number);
		$criteria->compare('summary',$this->summary,true);
		$criteria->compare('price',$this->price,true);
		if($this->active!='')
			$criteria->compare('active',$this->active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
		        'defaultOrder'=>'t.id DESC',
		    ),
		));
	}
}